#include "hla_processor.h"

class GroupsSizeProcessor : public HlaGroupsProcessor
{
public:
   GroupsSizeProcessor(){}
private:
    virtual ProcessorPriority get_priority() const  {   return 3.0f;    }
    virtual void process(const Group& group);
    virtual void generate_results(Spreadsheet& spreadsheet);

    map<string, size_t> group_size;
};

REGISTER_PROCESSOR(GroupsSizeProcessor);

void GroupsSizeProcessor::process(const Group& group)
{
    size_t seq_count = 0;
    FirstTimeFlag first_haplotype;

    for (list<Haplotype>::const_iterator haplotype = group.haplotypes.begin(); haplotype != group.haplotypes.end(); ++haplotype)
    {
        if (first_haplotype)
            seq_count = haplotype->sequences.size();
        else
        {
            if (seq_count != haplotype->sequences.size())
                cerr << "Error: different number of sequences among haplotypes in group " << group.name << endl;
        }
    }

    group_size[group.name] = seq_count;
}

void GroupsSizeProcessor::generate_results(Spreadsheet& spreadsheet)
{
    Sheet new_sheet( spreadsheet, "Groups" );

    // print header:
    Row(new_sheet) << "Group" << "#Seq";

    // print data:
    for (map<string, size_t>::const_iterator group = group_size.begin(); group != group_size.end(); ++group)
        Row(new_sheet) << group->first << group->second;
}

